package Repository;

import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;	
import org.xml.sax.helpers.DefaultHandler;

/**
*
* Rivera, Valencia, De Grano, Tan, Macatangay
*/
public class ConceptRepositoryHandler extends DefaultHandler
{
	private WordList wlist = new WordList();;
	private ArrayList<Word> tempList = new ArrayList<Word>();
	
	private Word tempWord;
	
	private boolean identifier = false;
	private boolean concept =  false;
	private boolean meaning = false;
		
	public void startElement(String uri, String localName,String qName,Attributes attributes) throws SAXException 
	{
		if(qName.equalsIgnoreCase("word"))
		{
			tempWord = new Word();
			identifier = true;
			concept = true;
			meaning = true;
		}
	}
	public void characters(char ch[], int start, int length) throws SAXException 
	{
		if(identifier)
		{
			tempWord.setIdentifier(new String(ch,start,length));
			identifier = false;
		}
		if(concept)
		{
			tempWord.setConcept(new String(ch,start,length));
			concept = false;
		}
		if(meaning)
		{
			tempWord.setMeaning(new String(ch,start,length));
			meaning = false;
		}	
	}
		
	public void endElement(String uri, String localName,String qName) throws SAXException 
	{
		if(qName.equalsIgnoreCase("word"))
		{
			tempList.add(tempWord);
		}
		if(qName.equalsIgnoreCase("root"))
		{
			wlist.setList(tempList);
		}
	}
}